#define _CRT_SECURE_NO_WARNINGS 1

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */


//struct ListNode* reverseList(struct ListNode* head) {
//    struct ListNode* p1 = head;
//    struct ListNode* p2 = head;
//    struct ListNode* p3 = NULL;
//    while (p1)
//    {
//        p2 = p1->next;
//        p1->next = p3;
//        p3 = p1;
//        p1 = p2;
//    }
//    return p3;
//}

struct ListNode* reverseList(struct ListNode* head)
{
	if (head == NULL || head->next == NULL)
	{
		return head;
	}
	struct ListNode* Newhead = reverseList(head->next);
	head->next->next = head;
	head->next = NULL;
	return Newhead;
}